package org.gwtmultipage.rebind.selector;

import com.google.gwt.core.ext.typeinfo.JClassType;
import org.gwtmultipage.rebind.EntryPointFactoryImplGenerator;

import java.io.PrintWriter;

/**
 * An entry point selector that selects based on an implementation-specific
 * condition.
 *
 * @author brian.ireilly
 */
public abstract class BaseEntryPointSelector implements EntryPointSelector {

	public void writeSelectionCode(JClassType classType,
	                               PrintWriter context) {
		String entryPoint = classType.getQualifiedSourceName();
		context.println("		if (" + generateMatchCondition(classType) + ") {");
		context.println("			" + EntryPointFactoryImplGenerator.ENTRY_POINT_VAR + " = \"" + entryPoint + "\";");
		context.println("		}");
	}

	protected abstract String generateMatchCondition(JClassType classType);
}
